package com.fzrskj.cloud.free.core.utils;

import ms.core.tool.PropTool;

/**
 * ConfigPropUtils.
 *
 * @author zj.
 *         Created on 2018/11/22 0022.
 */
public class ConfigPropUtils {
    private static String propFile = "/config/system.properties";
    private static String encryptKeyService = "sdq342@#$%3dde";
    private static String encryptKeyCustomer = "klsa32$@i098S";
    private static PropTool cfg;
    static {
        cfg = new PropTool(propFile);
        encryptKeyCustomer = cfg.getValue("encrypt.customer.key", encryptKeyCustomer);
        encryptKeyService = cfg.getValue("encrypt.service.key", encryptKeyService);
    }

    /**
     * 获取服务端数据加密密钥.
     * @return String
     */
    public static String getEncryptKeyService() {
        return encryptKeyService;
    }

    /**
     * 获取客户端约定加密密钥.
     * @return
     */
    public static String getEncryptKeyCustomer() {
        String pass = encryptKeyCustomer;
        if (pass.length() > 16) {
            pass = pass.substring(0,pass.length());
        } else if (pass.length() < 16) {
            int num = 16 - pass.length();
            for (int i=0; i<num; i++) {
                pass += "0";
            }
        }
        return pass;
    }

    /**
     * 获取system.properties配置值.
     * @param key 配置名称.
     * @return String.
     */
    public static String getValue(String key) {
        return getValue(key, null);
    }

    /**
     * 获取system.properties配置值.
     * @param key 配置名称.
     * @param defaultValue 默认值.
     * @return String.
     */
    public static String getValue(String key, String defaultValue) {
        return cfg.getValue(key, defaultValue);
    }
}
